using UnityEngine;
using System.Collections;

public class SceneGame_Bullet : MonoBehaviour
{
	
	private GameObject Player;
	public AudioClip FireSound;
	public AudioClip HitSound;
	public float Offset;
	public float Velocity;
	public float Delay;
	
	private float Timer;
	
	Vector3 Default;
	
	public void Start()
	{
		Default = transform.position;
		Player = GameObject.Find("PlayerPrefab");
	}
	
	public void Update()
	{
		if (SceneGame.Instance.Step > 1)
			return;
		
		float smoothDeltaTime = Mathf.Clamp(Time.smoothDeltaTime, 0.01666667f, float.MaxValue);
		if (Timer > 0.0f)
		{
			Timer = Mathf.Clamp(Timer - smoothDeltaTime, 0.0f, float.MaxValue);
			return;
		}
		OnTriggerEnter(null);
		if (Input.GetButton("Fire1") || Input.GetButton("Jump"))
		{
			audio.PlayOneShot(FireSound);
			transform.position = Player.transform.position + new Vector3(0.0f, 0.0f, Offset);
			rigidbody.velocity = new Vector3(0.0f, 0.0f, Velocity);
			Timer = Delay;
		}
	}
	
	public void OnTriggerEnter(Collider collider)
	{
		if ((collider != null) && (collider.name != "Wall"))
		{
			audio.PlayOneShot(HitSound);
			collider.transform.localScale *= 0.75f;
		}
		transform.position = Default;
		rigidbody.velocity = Vector3.zero;
	}
	
}